package com.ljs.myspringboot.controller;

import com.ljs.myspringboot.entity.Customer;
import com.ljs.myspringboot.service.CustomerService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/test")
@PropertySource("classpath:db.properties")/*导入propeties里面的属性*/
public class Controller {
    @Value("${db.name}")
    private String name;
    @Value("${db.age}")/*可以application.properties的属性*/
    private int age;
    @Value("${user.sex}")/*可以application.yml的属性*/
    private String sex;
    @Value("#{systemProperties['os.name']}")/*输出系统名*/
    private String local;

    @RequestMapping("/test")
    public String test() {
        System.out.println(name);
        System.out.println(age);
        System.out.println(sex);
        System.out.println(local);
        return "成功";

    }

    @Autowired
    CustomerService customerService;

    @RequestMapping("/my")
    public List<Customer> sel() {
        return customerService.selCus();
    }

    @RequestMapping("/convert")
    public Map<String, Object> convert() {
        Map<String, Object> map = new HashMap<>(16);
        map.put("name", "哈哈");
        return map;
    }

}
